﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using mitasoft.ERS.Web.Utils;
using System.Drawing;

namespace mitasoft.ERS.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            entityLatestActivity.Where = string.Format(" it.IDProject = {0} AND it.Title like '%{1}%' ", Session["SESSION_CurrentProjectID"] ?? 0, tbFilterTitle.Text ?? "");
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            BindCurrentProject();
            gridLastestActivity.RowDataBound += new GridViewRowEventHandler(gridLastestActivity_RowDataBound);
            btnFilter.Click += new EventHandler(btnFilter_Click);
        }

        void btnFilter_Click(object sender, EventArgs e)
        {
            entityLatestActivity.Where = string.Format(" it.IDProject = {0} AND it.Title like '%{1}%' ", Session["SESSION_CurrentProjectID"] ?? 0, tbFilterTitle.Text ?? "");
        }

        void gridLastestActivity_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            e.Row.BackColor = Color.AliceBlue;
        }

        void gridLastestActivity_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridLastestActivity.PageIndex = e.NewPageIndex;
            gridLastestActivity.DataBind();
        }


        private void BindCurrentProject()
        {
            ddlSelectedProject.SelectedIndexChanged += new EventHandler(ddlSelectedProject_SelectedIndexChanged);
            ddlSelectedProject.DataSource = Utils.CacheFactory.GetProjects;
            ddlSelectedProject.DataBind();

            int currentProjectID = SessionWrapper.GetFromSession<int>(SessionWrapper.SESSION_CurrentProjectID);

            if (currentProjectID > 0)
                ddlSelectedProject.SelectedValue = currentProjectID.ToString();
            else
                ddlSelectedProject.SelectedIndex = 0;

            if (!Page.IsPostBack)
                SaveSelectedProjectToSession();
        }

        void ddlSelectedProject_SelectedIndexChanged(object sender, EventArgs e)
        {
            SaveSelectedProjectToSession();
        }

        private void SaveSelectedProjectToSession()
        {
            SessionWrapper.AddToSession(SessionWrapper.SESSION_CurrentProjectID, Convert.ToInt32(ddlSelectedProject.SelectedValue));
            SessionWrapper.AddToSession(SessionWrapper.SESSION_CurrentProjectName, ddlSelectedProject.SelectedItem.Text);
            (this.Master as SiteMaster).UpdateMasterTitle();
        }


        public class BugMoc
        {
            public int ID { get; set; }
            public string Project { get; set; }
            public string Type { get; set; }
            public string Title { get; set; }


            public static List<BugMoc> GetData()
            {
                return new List<BugMoc>
                {
                    new BugMoc { ID = 101, Project="Predic.RO", Type = "Major", Title = "012345678901234567890123456789012345678901234567890123" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 5" },
                     new BugMoc { ID = 201, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 1" },
                    new BugMoc { ID = 202, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 2" },
                    new BugMoc { ID = 203, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 3" },
                    new BugMoc { ID = 204, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 4" },
                    new BugMoc { ID = 205, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 5" },
                     new BugMoc { ID = 301, Project="Predic.RO", Type = "Major", Title = "[Predic.RO] - Problema 1" },
                    new BugMoc { ID = 302, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 303, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 304, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 305, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 401, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 402, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 403, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 404, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 405, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 401, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 402, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 403, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 404, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 405, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 501, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 502, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 503, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 504, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 505, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 501, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 101, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 101, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 101, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 101, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                     new BugMoc { ID = 101, Project="Predic.RO", Type = "Major", Title = "Problema 1" },
                    new BugMoc { ID = 102, Project="Predic.RO", Type = "Major", Title = "Problema 2" },
                    new BugMoc { ID = 103, Project="Predic.RO", Type = "Major", Title = "Problema 3" },
                    new BugMoc { ID = 104, Project="Predic.RO", Type = "Major", Title = "Problema 4" },
                    new BugMoc { ID = 105, Project="Predic.RO", Type = "Major", Title = "Problema 5" },
                };
            }
        }
    }
}
